package org.ecjmn.pringles.other;

import java.util.Hashtable;
import org.ecjmn.pringles.analysis.DepthFirstAdapter;
import org.ecjmn.pringles.game.Deck;
import org.ecjmn.pringles.game.Hand;
import org.ecjmn.pringles.node.*;

public class CopyOfInterpreter extends DepthFirstAdapter {
	
	Hashtable<String,Deck> decks = new Hashtable<String,Deck>();
	Hashtable<String,Hand> hands = new Hashtable<String,Hand>();
	
	public void caseADeclarationStatement(ADeclarationStatement node) {
		String modifier = node.getModifier().toString().trim();
		String identifier = node.getIdentifier().toString().trim();
		
		System.out.println(modifier);
		if (modifier.equals("Deck")) {
			Deck deck = new Deck();
			decks.put(identifier, deck);
		}
		else if (modifier.equals("Hand")) {
			Hand hand = new Hand();
			hands.put(identifier, hand);
		}
	}
	
	public void caseAPutinExpStatement(APutinExpStatement node) {
		Deck fromDeck = decks.get(node.getId1().toString().trim());
		Hand toHand = hands.get(node.getId2().toString().trim());
		toHand.put(fromDeck.pop());
	}
	
	// pls update with the original one in Interpreter
	public void caseAPrintExpStatement(APrintExpStatement node) {
		String expression = node.getExpression().toString().trim();
		
		if (decks.containsKey(expression)) {
			decks.get(expression).print();
		}
		else if (hands.containsKey(expression)) {
			hands.get(expression).print();
		}
		else {
		
		}
	}
	
	public void caseAShuffleStatement(AShuffleStatement node) {
		String identifier = node.getIdentifier().toString().trim();
		
		if (decks.containsKey(identifier)) {
			decks.get(identifier).shuffle();
		}
		else if (hands.containsKey(identifier)) {
			hands.get(identifier).shuffle();
		}
		else {
		
		}
	}

}
